<?php

use App\Helpers\CSRF;
use App\Helpers\HTML;
use App\Helpers\URL;

if ($event !== 'profileUpdate') { ?>
<?php $app->render('templates/dashboard_open', ['app' => $app, 'title' => 'Mi cuenta']) ?>
  <main>
    <header class="text-center">
      <h1>Mi cuenta</h1>
      <figure>
        <?php if (isset($values['photo'])) { ?>
          <img src="" alt="" class="size-12 is-rounded">
        <?php } else { ?>
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="size-12">
            <path fill-rule="evenodd" d="M18.685 19.097A9.723 9.723 0 0 0 21.75 12c0-5.385-4.365-9.75-9.75-9.75S2.25 6.615 2.25 12a9.723 9.723 0 0 0 3.065 7.097A9.716 9.716 0 0 0 12 21.75a9.716 9.716 0 0 0 6.685-2.653Zm-12.54-1.285A7.486 7.486 0 0 1 12 15a7.486 7.486 0 0 1 5.855 2.812A8.224 8.224 0 0 1 12 20.25a8.224 8.224 0 0 1-5.855-2.438ZM15.75 9a3.75 3.75 0 1 1-7.5 0 3.75 3.75 0 0 1 7.5 0Z" clip-rule="evenodd" />
          </svg>
        <?php } ?>
      </figure>
    </header>
    <div class="card is-full-width max-w-lg mx-auto">
<?php } ?>
      <div id="profileUpdate">
        <?php if (isset($success)) { ?>
          <?php $app->render('components/success', ['success' => $success]) ?>
        <?php } if (isset($error)) { ?>
          <?php $app->render('components/error', ['error' => $error]) ?>
        <?php } ?>
        <form action="<?= URL::event('profile/update', null, 'profileUpdate') ?>" method="post" enctype="multipart/form-data" target=htmz>
          <input type="hidden" name="<?= CSRF::getVarname() ?>" value="<?= $app->local(CSRF::getVarname()) ?>">
          <p>
            <label for="photo">Foto</label>
            <input type="file" name="photo" id="photo" class="<?= $status['photo'] ?>">
            <small class="text-error"><?= HTML::esc($validations['photo']) ?></small>
          </p>
          <p>
            <label for="username">Usuario</label>
            <input type="text" name="username" id="username" placeholder="juanperez123" value="<?= HTML::esc($values['username']) ?>" class="<?= $status['username'] ?>">
            <small class="text-error"><?= HTML::esc($validations['username']) ?></small>
          </p>
          <p>
            <label for="email">Correo</label>
            <input type="email" name="email" id="email" placeholder="juan.perez@email.com" value="<?= HTML::esc($values['email']) ?>" class="<?= $status['email'] ?>">
            <small class="text-error"><?= HTML::esc($validations['email']) ?></small>
          </p>
          <p>
            <label for="password">Contraseña</label>
            <input type="password" name="password" id="password" placeholder="Ingresa tu contraseña" class="<?= $status['password'] ?>">
            <small class="text-error"><?= HTML::esc($validations['password']) ?></small>
          </p>
          <p>
            <label for="confirm_password">Confirmar contraseña</label>
            <input type="password" name="confirm_password" id="confirm_password" placeholder="Ingresa de nuevo tu contraseña" class="<?= $status['confirm_password'] ?>">
            <small class="text-error"><?= HTML::esc($validations['confirm_password']) ?></small>
          </p>
          <p class="text-right">
            <a href="<?= URL::site('contacts') ?>" class="button secondary">Cancelar</a>
            <input type="submit" value="Guardar" class="button primary">
          </p>
        </form>
      </div>
<?php if ($event !== 'profileUpdate') { ?>
    </div>
  </main>
<?php $app->render('templates/dashboard_close', ['app' => $app]) ?>
<?php } ?>
